﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for user_groupBus
/// </summary>
public class user_groupBus
{
    user_groupDAL usergroupDAL;
	public user_groupBus()
	{
		//
		// TODO: Add constructor logic here
		//
        usergroupDAL = new user_groupDAL();
	}

    public bool EditUserGroup(int user_group_id, string name, string permission)
    {
        if (usergroupDAL.EditUserGroup(user_group_id, name, permission) != 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public bool DeleteUserGroup(int user_group_id)
    {
        if (usergroupDAL.DeleteUserGroup(user_group_id) != 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public DataTable getAllUserGroup()
    {
        return usergroupDAL.getAllUserGroup();
    }
    public user_group getUserGroupByID(int user_group_id)
    {
        DataTable dt = usergroupDAL.getUserGroupByID(user_group_id);
        user_group usergroup = null;
        if (!dt.HasErrors || dt != null)
        {
            foreach (DataRow r in dt.Rows)
            {
                usergroup = new user_group(
                                Convert.ToInt32(r["user_group_id"]),
                                r["name"].ToString(),
                                r["permission"].ToString()
                            );
            }
        }
        return usergroup;
    }

}